package ihm_clarifiee.Presentation;

import ihm_clarifiee.Presentation.model_table.model_table_listeRelease;
import ihm_clarifiee.Control.CRelease;
import ihm_clarifiee.Control.CSprint;
import ihm_clarifiee.Presentation.model_table.model_table_histoire;
import ihm_clarifiee.Presentation.popup.Popup_Ajout_Histoire;
import ihm_clarifiee.Presentation.popup.popup;
import ihm_clarifiee.application.Histoire;
import ihm_clarifiee.application.Release;
import ihm_clarifiee.application.Sprint;

import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import javax.swing.JFrame;

import javax.swing.JPanel;

public class PSprint extends javax.swing.JPanel implements popup {
    CSprint controle;

    private model_table_histoire md;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JLabel lb_debut;
    private javax.swing.JLabel lb_fin;
    private javax.swing.JLabel lb_nom;
    private javax.swing.JLabel lb_obj;
    private javax.swing.JTextField tf_debut;
    private javax.swing.JTextField tf_fin;
    private javax.swing.JTextField tf_nom;
    private javax.swing.JTextField tf_obj;

    public PSprint(CSprint c) {
//    	System.out.println("PSprint.java");
        controle = c;

     
        initComponents();

        md=new model_table_histoire();

        tbl_principal.setModel(md);

        initModel();
        updateliste();

        this.setSize(1000,800);

    }

    public void updateliste()
    {
    md.removeAll();
   Iterator it = controle.getlisteHistoire().iterator();
    Histoire sl;
   while(it.hasNext())
   {
   sl =(Histoire)it.next();
   String [] t ={sl.getNom(),sl.getDescription(),sl.getDuree()+""};
    md.add(t);

   }
//  System.out.println("update ");
    this.repaint();
    tbl_principal.repaint();
    if( controle.getPresentation()!=null)
    controle.getPresentation().repaint();
    }

  

/*
    public void refreshFields(){
        String[] infos = controle.getInfos();
        tf_nom.setText(infos[0]);
        tf_obj.setText(infos[1]);
        tf_debut.setText(infos[2]);
        tf_fin.setText(infos[3]);
    }
 *

    public void modifierRelease(){
        String nom = tf_nom.getText();
        String obj = tf_obj.getText();
        Date debut = new Date(Integer.parseInt(tf_debut.getText(),2),Integer.parseInt(tf_debut.getText(),2),Integer.parseInt(tf_debut.getText(),4));
        Date fin = new Date(Integer.parseInt(tf_fin.getText(),2),Integer.parseInt(tf_fin.getText(),2),Integer.parseInt(tf_fin.getText(),4));

        controle.modifierRelease(nom, obj, debut, fin);
    }
*/
    public CSprint getControle(){
        return controle;
    }

    public void setEditable(boolean b){
       tf_debut.setEditable(b);
       tf_fin.setEditable(b);
       tf_nom.setEditable(b);
       tf_obj.setEditable(b);
    }



    private void initModel ()
    {
        tbl_principal.getColumnModel().getColumn(0).setMinWidth(20);
        tbl_principal.getColumnModel().getColumn(0).setPreferredWidth(150);
        tbl_principal.getColumnModel().getColumn(0).setMaxWidth(2000);
        tbl_principal.getColumnModel().getColumn(1).setMinWidth(30);
        tbl_principal.getColumnModel().getColumn(1).setPreferredWidth(300);
        tbl_principal.getColumnModel().getColumn(1).setMaxWidth(4500);
        tbl_principal.getColumnModel().getColumn(2).setMinWidth(50);
        tbl_principal.getColumnModel().getColumn(2).setPreferredWidth(50);
        tbl_principal.getColumnModel().getColumn(2).setMaxWidth(4000);
        tbl_principal.getColumnModel().getColumn(3).setMinWidth(100);
        tbl_principal.getColumnModel().getColumn(3).setPreferredWidth(150);
        tbl_principal.getColumnModel().getColumn(3).setMaxWidth(4000);
        tbl_principal.getColumnModel().getColumn(0).setResizable(true);
        tbl_principal.getColumnModel().getColumn(1).setResizable(true);
        tbl_principal.getColumnModel().getColumn(2).setResizable(true);
        tbl_principal.getColumnModel().getColumn(3).setResizable(true);
        tbl_principal.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);




     }

    private void initComponents() {

        panelVertical = new JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbl_principal = new javax.swing.JTable();
        bt_ajouter = new javax.swing.JButton();
        bt_suppr = new javax.swing.JButton();
        bt_modifier = new javax.swing.JButton();

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();


        jScrollPane1.setViewportView(tbl_principal);



        bt_ajouter.setText("Ajouter");
        bt_ajouter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_ajouterActionPerformed(evt);
            }
        });

        bt_suppr.setText("Suppr");

          bt_suppr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_supprActionPerformed(evt);
            }


        });

        bt_modifier.setText("Modifier");




            bt_modifier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modifierActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText("Liste des histoires");
        jLabel1.setMaximumSize(new java.awt.Dimension(146, 124));






        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

                            .addComponent(bt_suppr, 98, 98,98)
                            .addComponent(bt_ajouter, 98, 98, 98)
                            .addComponent(bt_modifier, 98, 98, 98)

                            ))
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                    //.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE))
                     )
               .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(9, 9, 9)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(bt_ajouter)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_modifier)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_suppr)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

                        .addGap(123, 123, 123)

                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        )
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(9, 9, 9)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    //.addComponent(jScrollPane2, 43,43, Short.MAX_VALUE)
                     
                .addContainerGap())
        );

    }

    private void bt_monterActionPerformed(java.awt.event.ActionEvent evt) {
    	   // updateliste();
    	       // projet.getPresentation().updateListeReleases();
    	    }

    private void bt_ajouterActionPerformed(java.awt.event.ActionEvent evt) {
        //JFrame popup = new Popup_Ajout(fake_table, m_modele_table);
    //	popup.setVisible(true);
    }

    private void bt_descendreActionPerformed(java.awt.event.ActionEvent evt) {

        tbl_principal.repaint();
   }

  private void bt_modifierActionPerformed(java.awt.event.ActionEvent evt) {

            }
  private void bt_detailActionPerformed(ActionEvent evt) {

		// TODO Auto-generated method stub

	}
	private void bt_supprActionPerformed(ActionEvent evt) {
		// TODO Auto-generated method stub

	}

    private javax.swing.JTable tbl_principal;

    private JPanel panelVertical;

    private javax.swing.JButton bt_ajouter;


    private javax.swing.JButton bt_modifier;

    private javax.swing.JButton bt_suppr;

    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;

    public boolean valider() {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}

